# Maintainer: Daniel Sabogal <dsabogalcc@gmail.com>
pkgname=openmpi
pkgver=4.1.6
pkgrel=0
pkgdesc="Message passing library for high-performance computing"
url="https://www.open-mpi.org/"
arch="all"
license="custom" # BSD-based custom license
makedepends="perl gfortran hwloc-dev libevent-dev libgomp"
subpackages="$pkgname-dev $pkgname-doc"
source="https://www.open-mpi.org/software/ompi/v${pkgver%.*}/downloads/openmpi-$pkgver.tar.bz2"

build() {
	local disable_atomics=""
	case "$CARCH" in
		ppc64le) disable_atomics="--disable-builtin-atomics";;
	esac

	CFLAGS="$CFLAGS -O2 -flto=auto" \
	CXXFLAGS="$CXXFLAGS -O2 -flto=auto" \
	./configure \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--sysconfdir=/etc/$pkgname \
		--enable-ipv6 \
		--with-threads=posix \
		--with-hwloc=/usr \
		--disable-static \
		$disable_atomics
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

	# apk doesn't accept this version
	sed -i "s|rc1||" "$pkgdir"/usr/lib/pkgconfig/pmix.pc
}

dev() {
	default_dev

	local bins="mpiCC mpic++ mpicc mpicxx mpif77 mpif90 mpifort
		ortecc opal_wrapper"

	local i; for i in $bins; do
		amove usr/bin/$i
	done
}

sha512sums="
0ef3240f9c436fb19b67e836cac376eafeb7825d12de3387dad04329dee9f182799d17d785ea23eba763810f479015bb5230593c28950b616b2f0aa1c0a81e71  openmpi-4.1.6.tar.bz2
"
